package com.sjzxywlkj.cplife.alipay.result;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alipay.api.AlipayApiException;
import com.alipay.api.domain.CPAliveBillEntrySet;
import com.alipay.api.domain.CPBillResultSet;
import com.alipay.api.response.AlipayEcoCplifeBillBatchUploadResponse;
import com.alipay.api.response.AlipayEcoCplifeBillBatchqueryResponse;
import com.alipay.api.response.AlipayEcoCplifeBillDeleteResponse;
import com.alipay.api.response.AlipayEcoCplifeBillModifyResponse;
import com.sjzxywlkj.cplife.alipay.conn.BillConn;
import com.sjzxywlkj.cplife.alipay.request.entity.BillBatchquery;
import com.sjzxywlkj.cplife.alipay.request.entity.BillBatchupload;
import com.sjzxywlkj.cplife.alipay.request.entity.BillDelete;
import com.sjzxywlkj.cplife.alipay.request.entity.BillModify;
import com.sjzxywlkj.cplife.alipay.response.entity.*;

/**
 * 账单操作返回结果
 */
public class BillAlipay {

    //批量上传待缴物业费账单
    public static Map<String, Object> batchUpload(BillBatchupload billBatchupload, String app_auth_token) throws AlipayApiException {
        AlipayEcoCplifeBillBatchUploadResponse response = BillConn.batchUpload(billBatchupload, app_auth_token);

        Map<String, Object> result = new HashMap<String, Object>();
        PublicParameters parameters = new PublicParameters(response.getCode(), response.getMsg(), response.getSubCode(), response.getSubMsg(), null);
        BillBatchuploadResult billBatchuploadResult = new BillBatchuploadResult(response.getBatchId());
        result.put("parameters", parameters);
        result.put("billBatchuploadResult", billBatchuploadResult);
        return result;


    }

    // 删除已上传的物业费账单数据
    public static Map<String, Object> delete(BillDelete billDelete, String app_auth_token) throws AlipayApiException {
        AlipayEcoCplifeBillDeleteResponse response = BillConn.delete(billDelete, app_auth_token);


        Map<String, Object> result = new HashMap<String, Object>();
        PublicParameters parameters = new PublicParameters(response.getCode(), response.getMsg(), response.getSubCode(), response.getSubMsg(), null);
        List<Alive_bill_entry_list> alive_bill_entry_list = new ArrayList<Alive_bill_entry_list>();

        if (response.getAliveBillEntryList() != null) {
            for (CPAliveBillEntrySet cSet : response.getAliveBillEntryList()) {
                Alive_bill_entry_list aList = new Alive_bill_entry_list(cSet.getBillEntryId(), cSet.getStatus());
                alive_bill_entry_list.add(aList);
            }
        }

        BillDeleteResult billDeleteResult = new BillDeleteResult(alive_bill_entry_list);
        result.put("parameters", parameters);
        result.put("billDeleteResult", billDeleteResult);
        return result;

    }

    //修改已上传的物业费账单数据
    public static Map<String, Object> modify(BillModify billModify, String app_auth_token) throws AlipayApiException {
        AlipayEcoCplifeBillModifyResponse response = BillConn.modify(billModify, app_auth_token);


        Map<String, Object> result = new HashMap<String, Object>();

        PublicParameters parameters = new PublicParameters(response.getCode(), response.getMsg(), response.getSubCode(), response.getSubMsg(), null);
        List<Alive_bill_entry_list> alive_bill_entry_list = new ArrayList<Alive_bill_entry_list>();

        if (response.getAliveBillEntryList() != null) {
            for (CPAliveBillEntrySet cSet : response.getAliveBillEntryList()) {
                Alive_bill_entry_list aList = new Alive_bill_entry_list(cSet.getBillEntryId(), cSet.getStatus());
                alive_bill_entry_list.add(aList);
            }
        }
        BillModifyResult billModifyResult = new BillModifyResult(alive_bill_entry_list);
        result.put("parameters", parameters);
        result.put("billModifyResult", billModifyResult);
        return result;


    }

    //物业费账单数据批量查询
    public static Map<String, Object> batchQuery(BillBatchquery billBatchquery, String app_auth_token) throws AlipayApiException {
        AlipayEcoCplifeBillBatchqueryResponse response = BillConn.batchQuery(billBatchquery, app_auth_token);


        Map<String, Object> result = new HashMap<String, Object>();
        PublicParameters parameters = new PublicParameters(response.getCode(), response.getMsg(), response.getSubCode(), response.getSubMsg(), null);
        List<Bill_result_set> bill_result_set = new ArrayList<Bill_result_set>();
        if (response.getBillResultSet() != null) {
            for (CPBillResultSet cpBillResultSet : response.getBillResultSet()) {
                Bill_result_set bSet = new Bill_result_set(cpBillResultSet.getBillEntryId(), cpBillResultSet.getOutRoomId(), cpBillResultSet.getRoomAddress(), cpBillResultSet.getCostType(), cpBillResultSet.getBillEntryAmount(), cpBillResultSet.getAcctPeriod(), cpBillResultSet.getReleaseDay(), cpBillResultSet.getDeadline(), cpBillResultSet.getStatus());
                bill_result_set.add(bSet);
            }
        }
        BillBatchqueryResult billBatchqueryResult = new BillBatchqueryResult(new Long(response.getCurrentPageNum()).intValue(), new Long(response.getTotalBillCount()).intValue(), bill_result_set);
        result.put("parameters", parameters);
        result.put("billBatchqueryResult", billBatchqueryResult);
        return result;


    }
}
